﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;
using System.Text.RegularExpressions;
using System.Linq;

namespace TRIG_MOD_DASHBOARDS.PendingTasksByPerson
{
    public partial class PendingTasksByPersonUserControl : UserControl
    {
        private static string Entity { get; set; }
        DataForUsersTasks objCls = new DataForUsersTasks();

        protected void Page_Load(object sender, EventArgs e)
        {
            errorMsg.Text = "";
            gvUserPendingTasks.DataSource = null;
            gvUserPendingTasks.DataBind();
            objCls.errorMsg = errorMsg;
            Entity = Entities(Convert.ToString(objCls.GetUserEntity()));
            
            if (IsPostBack) { }
            else
            { objCls.getEntityUsers(ddlTaskPerson, Entity); }
        }

        private static string Entities(string QS)
        {
            string ent = "";
            if (QS == "CNT") { ent = "Contractor"; } else if (QS == "CNS") { ent = "Consultant"; } else ent = "Client";
            return ent;
        }

        protected void ddlTaskPerson_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvUserPendingTasks.DataSource = null;
            gvUserPendingTasks.Visible = false;
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            gvUserPendingTasks.DataSource = null;
            gvUserPendingTasks.DataBind();
            gvUserPendingTasks.Visible = false;
            errorMsg.Text = "";
        }

        protected void lnkCompUsers_Click(object sender, EventArgs e)
        {
            objCls.errorMsg = errorMsg;
            SPFieldUserValue teskUser = new SPFieldUserValue(SPContext.Current.Site.OpenWeb(),ddlTaskPerson.SelectedItem.Text);
            int gvCount =objCls.FormLoadBindData(Convert.ToString(teskUser.User), gvUserPendingTasks);
            if (gvCount > 0) { gvUserPendingTasks.Visible = true; errorMsg.Text = ""; } else { gvUserPendingTasks.Visible = false; }

        }

        protected void gvUserPendingTasks_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvUserPendingTasks.PageIndex = e.NewPageIndex;
            gvUserPendingTasks.DataBind();
        }

        protected void gvUserPendingTasks_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           objCls.Row_Data_Bind(e);
        }

       
        protected void btnPendingShow_Click(object sender, EventArgs e)
        {
            int gvCount=0;
            objCls.errorMsg = errorMsg;
            //SPFieldUserValue teskUser = new SPFieldUserValue(SPContext.Current.Site.OpenWeb(), ddlTaskPerson.SelectedItem.Value);
            try
            {
                gvCount = objCls.FormLoadBindData(Convert.ToString(ddlTaskPerson.SelectedItem.Value), gvUserPendingTasks);
            }
            catch (Exception x)
            {
                objCls.ErrLos(x);
            }
            
            if (gvCount > 0) { gvUserPendingTasks.Visible = true; errorMsg.Text = ""; } else { gvUserPendingTasks.Visible = false; errorMsg.Text = "No Records found"; errorMsg.ForeColor = System.Drawing.Color.Green; }
        }

    }
}
